#region Using Statements
using System;
using System.Xml;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.Runtime.Remoting;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
#endregion

namespace SkyBurner
{
    public class ShadersManager : BaseObject
    {
        protected Collection<CustomShader> m_shadersBag;

        public ShadersManager(BaseGame pGame)
            : base(pGame)
        {
            m_shadersBag = new Collection<CustomShader>();
        }

        public void Load(String pXMLShadersFile)
        {
            XmlDocument xmlShadersFile = new XmlDocument();

            xmlShadersFile.Load(pXMLShadersFile);

            XmlNode xmlRootNode = xmlShadersFile.DocumentElement;
            foreach (XmlNode xmlShaderNode in xmlRootNode.ChildNodes)
            {
                String shaderName = xmlShaderNode.Attributes["Name"].Value;
                String shaderClassHandler = xmlShaderNode.Attributes["ClassHandler"].Value;
                String shaderEffectFile = xmlShaderNode.Attributes["EffectFile"].Value;

                ObjectHandle objectHandle = Activator.CreateInstance(null, shaderClassHandler);
                CustomShader customShader = (CustomShader)objectHandle.Unwrap();

                customShader.Load(m_Game, shaderEffectFile);

                m_shadersBag.Add(customShader);
            }
        }

        public CustomShader GetShader(String pShaderName)
        {
            foreach (CustomShader customShader in m_shadersBag)
            {
                if (customShader.ShaderName == pShaderName)
                    return customShader; // customShaderRet;
            }
            return null;
        }
    }
}
